use crate::proc_macro::TokenStream;
// use syn::{parse_macro_input, AttributeArgs, Data, ReturnType};

pub fn impl_macro(ast: &syn::DeriveInput) -> TokenStream {
    let name = &ast.ident;
    let code = quote::quote! {

        impl std::fmt::Debug for #name {
            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                let s = self.to_string();
                f.write_str(&s)
            }
        }

        impl std::fmt::Display for #name {
            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
                write!(f, "{}", self.to_string())
            }
        }

        impl #name {
            pub fn get_iter() -> Box<dyn Iterator<Item = Self>> {
                Box::new(Self::iter())
            }
            /// to_string()方法把实体格式化
            pub fn to_string(&self) -> String {
                use serde_json::Value as JsonV;
                let json_v: JsonV = serde_json::to_value(self).unwrap_or_default();
                let content = match json_v {
                    JsonV::String(v) => v,
                    JsonV::Number(v) => v.to_string(),
                    _ => json_v.to_string(),
                };
                content
            }
            pub fn get_vec() -> Vec<Self> {
                Self::iter().collect::<Vec<Self>>()
            }
            pub fn get(s: impl Into<String>) -> Option<Self> {
                let s = s.into();
                Self::get_iter().find(|v| v.to_string() == s)
            }
        }
    };
    // let code = code.to_string().replace('\n', "");
    // let code = quote::quote! {#code};
    code.into()
}
